<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
    $this->display('index');
}

  
   //登录验证  
    public function checkLogin(){
      if($_POST){
           $userModel=D('AdminUser');
           $map['user_name']=$_POST['username'];
           $password = sha1($_POST['password']);
            $res= $userModel->where($map)->find();

            if(sha1($_POST['password']) ==$res['user_pwd']){
              session('user',$res);
              $this->redirect('Index/index');
            }else{
              $this->error('用户名或密码错误!');
            }
      }else{
        $this->error('非法访问!');
      }
    } 
    
   //修改密码
    public function news_password(){
     $password =$_POST['password'];
     $password_confirmation =  $_POST['password_confirmation'];
    if($password !=$password_confirmation){
       $this->error('密码不一致!');
    }else{
      $userModel=D('Users');
      $data['password'] = sha1($password);
      $user = session('user');
      $map['id'] = $user['id'];
      $res = $userModel ->where($map)->save($data);
        if($res != flase){
           session_destroy(); 
           $this->redirect('index');
        }else{
           $this->error('非法操作!');
        }
    }

    }

    
    //退出登录
    public function logout(){
        session_destroy();  //清除服务器的sesion文件
        $this->redirect('Login/index');
    }

}
?>